<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>业务流程管理</title>
    <jsp:include page="../../../head.jsp"/>
    <script type="text/javascript">
        var processState = $.mrdForm.ajaxdp("dropdown-processState");

        var formSetting = {
            title: "业务流程管理",
            module: 'save',
            numCount: 2,
            columns: [
                {
                    name: "processName",
                    label: "业务流程名称",
                    width: 10,
                    validate: "validate[required]"
                }, {
                    name: "processState",
                    label: "业务流程状态",
                    type: "dropdown",
                    minLength: 0,
                    data: processState,
                    validate: "validate[required]"
                }, {
                    name: "remarks",
                    label: "业务流程备注",
                    type: "textarea"
                }, {
                    name: "processId",
                    hidden: true
                }, {
                    name: "bizType",
                    hidden: true
                }, {
                    name: "delState",
                    hidden: true
                }
            ],
            buttons: {
                query: false,
                custom: [
                    {
                        value: "返回",
                        click: function () {
                            history.back();
                        }
                    }
                ]
            },
            form: {
                'url': "process-saveOrUpdateProcess",
                'data': function () {
                    var id = "${process.processId}";
                    var bizType = "${process.bizType}";
                    if (id) {
                        var dataValue = new Object();
                        $.ajax({
                            url: "process-getData?processId=" + id + "&bizType=" + bizType,
                            method: "post",
                            async: false,
                            success: function (data) {
                                //TODO processState
//                                $.each(processState, function (i, n) {
//                                    if (data.processState == n[1]) {
//                                        var dropdownName = $.mrdForm.getDropDwonLabelName("processState");
//                                        data[dropdownName] = n[0];
//                                    }
//                                });
                                dataValue = data;
                            }
                        });
                        return dataValue;
                    } else {
                        var dataValue = new Object();
                        dataValue.process = new Object();
                        dataValue.bizType = bizType;
                        return dataValue;
                    }
                },
                'ajaxForm': {
                    success: function (data) {
                        alert(data.msg);
                    }
                }
            }
        };

        $(document).ready(function () {
            //初始化表单验证引擎
            $("#userForm").validationEngine("attach", {
                //消息位置
                promptPosition: "bottomRight",
                scroll: false
            });
            //初始化ajaxForm参数
            var options = {
                //提交方式
                type: "POST",
                //提交数据格式
                dataType: "json",
                //在提交之前做的操作
                beforeSubmit: function () {
                    return $("#userForm").validationEngine("validate");
                },
                //成功后做的操作
                success: function (responseText, statusText, xhr, $form) {
                    alert(responseText.msg);
                    location.href = "process-find?bizType=" + $("#bizType").val();
                }
            };
            $('#userForm').ajaxForm(options);
            $("#userForm").mrdForm(formSetting);
        });
        function submitTheForm() {
            $("#userForm").submit();
        }
    </script>
</head>
<body>
<form id="userForm">

</form>
</body>
</html>
